

function delIndexInfo(){
	var listsize = jQuery('#listsize').val();
	var pkid_string = '';
	var pkid_cust_string = '';
	for(var i=1;i<=listsize;i++){
	var listsizei = jQuery('#listsize'+i).val();
	pkid_cust_string += jQuery('#checkall' + i).val() +'|';
		for(var j=1;j<=listsizei;j++){
					if( jQuery('#' + i + 'checkone' + j).is(':checked')){
						if(listsizei==1)
							pkid_string += jQuery('#' + i + 'checkone' + j +':checked').val();
						else
							pkid_string += jQuery('#' + i + 'checkone' + j +':checked').val()+'|';
					}
			}
	}
	if(pkid_string == ''){
		alert('请至少选择一条!'); 
	}else{
	if(window.confirm('确认删除吗?')){
		ShopCartOperating(pkid_cust_string='100000000000000',pkid_string,'3');
	}
	}
}

function selectSingle(){
	var listsize = jQuery('#listsize').val();
	for(var i=1;i<=listsize;i++){
		var listsizei = jQuery('#listsize'+i).val();
	if(jQuery('input:checkbox:[name*="'+i+'checkone"]:checked').length == listsizei) {
		jQuery('#checkall' + i).attr('checked', true);
	}else{
		jQuery('#checkall' + i).attr('checked', false);
	}
	}
	
	if(jQuery('input:checkbox:[name*="checkall"]:checked').length == listsize) {
		jQuery('#selectAllItems').attr('checked', true);
	}else{
		jQuery('#selectAllItems').attr('checked', false);
	}
	
}

function selectAll(){
	var listsize = jQuery('#listsize').val();
	for(var i=1;i<=listsize;i++){
		var listsizei = jQuery('#listsize'+i).val();
		for(var j=1;j<=listsizei;j++){
			if(jQuery('#checkall' + i).is(':checked')){
				jQuery('#'+i+'checkone'+j).attr('checked', true);
			}else{
				jQuery('#'+i+'checkone'+j).attr('checked', false);
			}
		}
	if(jQuery('input:checkbox:[name*="'+i+'checkone"]:checked').length == listsizei) {
		jQuery('#checkall' + i).attr('checked', true);
	}else{
		jQuery('#checkall' + i).attr('checked', false);
	}
	}
if(jQuery('input:checkbox:[name*="checkall"]:checked').length == listsize) {
		jQuery('#selectAllItems').attr('checked', true);
	}else{
		jQuery('#selectAllItems').attr('checked', false);
	}
}


function selectAllItems(){
	var listsize = jQuery('#listsize').val();
	for(var i=1;i<=listsize;i++){
		var listsizei = jQuery('#listsize'+i).val();
			
			if(jQuery('#selectAllItems').is(':checked')){
				//jQuery('#checkall'+i).attr('checked', true);
					for(var j=1;j<=listsizei;j++){
						//if(jQuery('#checkall' + i).is(':checked')){
							jQuery('#'+i+'checkone'+j).attr('checked', true);
						//}else{
						//	jQuery('#'+i+'checkone'+j).attr('checked', false);
					//	}
					}
			}else{
				//jQuery('#checkall'+i).attr('checked', false);
				//jQuery('#checkall'+i).attr('checked', false);
					for(var j=1;j<=listsizei;j++){
						//if(jQuery('#checkall' + i).is(':checked')){
						//	jQuery('#'+i+'checkone'+j).attr('checked', true);
						//}else{
							jQuery('#'+i+'checkone'+j).attr('checked', false);
						//}
					}
			}

	}
}

//更新购物车中的批量货物
function updatedWholesaleGoods(j,cust_id,goods_id,operatecode,type){
	//价格
	var goods_id_form = goods_id.replace(/\//g,"\\/");
	var nums_srt = jQuery('#buy_num_'+goods_id_form).val();
	var unit_num = jQuery('#nums'+j).val();
	var price = parseFloat(jQuery('#shop_price_'+goods_id_form).html().match(/\d+(\.\d*)?/gm));
	var integralNum = parseInt(jQuery('#IntegralNum_'+goods_id).val());
	//alert(nums_srt);
	var buyNum = 0;
	//如果为减少
	if(type == "1"){
		buyNum = parseInt(nums_srt) - parseInt(unit_num);
		if(buyNum < parseInt(unit_num)){
			alert("购买个数过少！");
			return;
		}
	//如果增加
	}else if(type == "2"){
		buyNum = parseInt(nums_srt) + parseInt(unit_num);
	}

	jQuery.ajax({	
		type: 'POST',
		url: '/templets/html/shop/jsp/shopingServices.jsp',
		data:'cust_id='+cust_id+'&goods_id='+goods_id+'&goodsprice='+price+'&operatecode='+operatecode+'&buy_num='+buyNum,
		success: function(response){
					$('#hiddenData').html(response);
					$('#goods_subtotal_'+goods_id).html('￥' + parseFloat(buyNum * price).toFixed(2));
					$('#goodsIntegralNum_'+goods_id).text(buyNum * integralNum);
					$('#totalGoodsCount').html($('#totalCountRemote').html());
					$('#buycart_nums').text($('#totalCountRemote').html());
					$('#totalIntegralNum1').html($('#totalIntegralNumRemote').html());
					$('.totalPrice').html((parseFloat($('#totalPriceRemote').html())).toFixed(2));
					$('#gift_ids').html($('#gift_idsRemote').html());
				}
	});
}

function changeWholesaleNum(j,cust_id,goods_id,operatecode,type){
	var array = new Array();
	var price = document.getElementById('shop_price_'+goods_id);
	//var buyNum = jQuery("#buy_num_"+goods_id).val();
	 var buyNum = document.getElementById("buy_num_"+goods_id);

	var len = $(".nums"+j).length;
		//alert(len);
		if(type=="2"){
			for(var i = 0;i<len;i++){
				var num =$(".nums"+j)[i];			
				if(buyNum.value == $(num).val()&& i<len-1){
					num =$(".nums"+j)[i+1];
					//alert($(num).val());	
					//$("#buy_num_"+j).val($(num).val());
					buyNum.value = $(num).val();
				}
			}
		}else if(type=="1"){
			for(var i = 0;i<len;i++){
				var num =$(".nums"+j)[i];			
				if(buyNum.value == $(num).val()&& i>0){
					num =$(".nums"+j)[i-1];
					//alert($(num).val());	
					//$("#buy_num_"+j).val($(num).val());
					buyNum.value = $(num).val();
				}
			}
		
		}
		//alert(goods_id);
		$(".nums"+j).each(function(index){
				if(buyNum.value == $(this).val()){
						//alert($("#price"+i+index).html()); 得到对应价格
						goods_price = $("#singleP"+j+index).val();
							//alert(goods_price);
						//$('#shop_price_'+goods_id).html(1000);
						price.innerHTML = goods_price;
						//alert(price.innerHTML);
						
				}		
		});
		ShopCartOperating(cust_id,goods_id,"2");
}

function ShopCartOperating(cust_id,goods_id,operatecode) {
var price = 0;
var nums =0;
var props ="";
var subtotal =0;
var totalPrice = 0;
var xxprice = "";
var xxcount = "";
var integralNum = 0;
var goods_id_tem = goods_id;

goods_id = goods_id.replace(/\//g,"\\/");

	if(operatecode == 1 ){
		var price_srt = jQuery('#set_price'+goods_id).val();
		var nums_srt = jQuery('#shopnum'+goods_id).val();
		if(nums_srt == '') nums_srt = '1';
		if(price_srt == '') price_srt = '1';	
		 price = parseFloat(price_srt);
		 nums = parseInt(nums_srt);
		 props = jQuery('#prop'+goods_id).val();
	}

	if(operatecode == 2){	
		var nums_srt = jQuery('#buy_num_'+goods_id).val();
		//alert(nums_srt);
		if(nums_srt == '') nums_srt = '1';		
		nums = parseInt(nums_srt);
		integralNum = parseInt(jQuery('#IntegralNum_'+goods_id).val());
		price = parseFloat(jQuery('#shop_price_'+goods_id).html().match(/\d+(\.\d*)?/gm));
		//price = document.getElementById('shop_price_'+goods_id).innerHTML;
		//alert(price);
	}

	jQuery.ajax({	
		type: 'POST',
		url: 'shopingServices.jsp',
		data:'cust_id='+cust_id+'&goods_id='+goods_id_tem+'&goodsprice='+price+'&operatecode='+operatecode+'&buy_num='+nums+'&goods_props='+props+'&num='+Math.round(Math.random()*10000)+'',
		success: function(response){
		jQuery('#hiddenData').html(response);

		if(operatecode == 3){//删除
			//jQuery('#goods_'+goods_id).hide("slow");
			var custArr = cust_id.split('|');
			var goodsArr = goods_id.split('|');
			var singleCount = parseInt(jQuery('#singleCustCountRemote').html())

			jQuery.each(goodsArr,function(){
			jQuery('#goods_'+this).css('display','none');
			});
			if(singleCount == 0){
			jQuery.each(custArr,function(){
			jQuery('#custInfo_'+this).css('display','none');
			});
			}

			jQuery('#totalGoodsCount').html(jQuery('#totalCountRemote').html());
			jQuery('#buycart_nums').text(jQuery('#totalCountRemote').html());
			jQuery('#totalIntegralNum1').html(jQuery('#totalIntegralNumRemote').html());
			jQuery('.totalPrice').html((parseFloat(jQuery('#totalPriceRemote').html())).toFixed(2));
			jQuery('#gift_ids').html(jQuery('#gift_idsRemote').html());
		}

		if(operatecode == 2){//更新数目
			
			jQuery('#goods_subtotal_'+goods_id).html('￥' + parseFloat(nums * price).toFixed(2));
			jQuery('#goodsIntegralNum_'+goods_id).text(nums * integralNum);
			jQuery('#totalGoodsCount').html(jQuery('#totalCountRemote').html());
			jQuery('#buycart_nums').text(jQuery('#totalCountRemote').html());
			jQuery('#totalIntegralNum1').html(jQuery('#totalIntegralNumRemote').html());
			jQuery('.totalPrice').html((parseFloat(jQuery('#totalPriceRemote').html())).toFixed(2));
			jQuery('#gift_ids').html(jQuery('#gift_idsRemote').html());
		}

		}
	});
	
	//alert("jQuery('#shop_price_'+goods_id).html()=="+jQuery('#shop_price_'+goods_id).html());
}




function setGoodsAttr(num,goods_id)
{
	var zongValue = '',zongName='';
	for(var i=0;i<num;i++){
		var attrvalue = document.getElementsByName("attrvalue"+i);
		if(attrvalue!=null){
			for(var j=0;j<attrvalue.length;j++){
				if(attrvalue[j].checked){
					var attrR = attrvalue[j].value.split("=");;

					zongValue += attrR[0];
					zongName += attrR[1];
				}
			}
		}
	}
	self.parent.document.getElementById('goods_attr').value = zongValue;
	self.parent.document.getElementById('goods_attr_id_'+goods_id).innerHTML = zongName;
	self.parent.tb_remove();
	//self.parent.window.location.href='/templets/html/default/b2c/jsp/shopingServices.jsp?goods_props='+zongName+'&goods_id='+goods_id+'&type=0';
	
	//alert(zongName);
} 

function checkGoodsStock(goods_id){
	
	var goods_stock_tem = jQuery('input[id^="buy_num_'+goods_id+'"]');
	var all_stock = 0;
		jQuery.each(goods_stock_tem,function(){
		all_stock = all_stock + parseInt(this.value);
		});
		return all_stock;
}










